<!--会员钱包变化记录管理-->
<template>
  <div id="memberUserWalletChange" class="app-container">
    <!--搜索条件-->
    <div class="filter-container">
      <el-form :model="listQuery" :inline="true">
        <el-form-item>
          <el-select v-model="listQuery.type" clearable filterable placeholder="请选择状态">
            <el-option label="全部" value="" />
            <el-option label="收入" value="1" />
            <el-option label="消费" value="0" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-date-picker
            v-model="applicationTimes"
            type="daterange"
            align="right"
            unlink-panels
            value-format="timestamp"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            :picker-options="pickerOptions" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" plain @click="handleFilter">搜索</el-button>
          <el-button icon="el-icon-refresh" plain @click="handleReset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>

    <!--列表-->
    <div class="table-container flex-main">
      <div class="table-container-header">
        <table-toolbar :create="false" :remove="false" @refresh="handleFilter">
          <template slot="rightTool">
            <export-drop-down :actions="['memberUserWalletChangeExportData','memberUserWalletChangeGetExportProcessStatus']" :list-query="listQuery" :async="true" text="钱包记录清单" />
          </template>
        </table-toolbar>
      </div>
      <el-table
        ref="multipleTable"
        :data="list"
        header-cell-class-name="table-header"
        fit
        height="100%"
        highlight-current-row
        @selection-change="handleSelectionChange"
        @row-click="handleRowClick"
        @sort-change="sortChange">
        <el-table-column type="selection" width="60" />
        <el-table-column align="center" prop="id" label="#" width="60">
          <template slot-scope="scope">{{ scope.$index+1 }}</template>
        </el-table-column>
        <el-table-column label="类型" prop="type" width="100" sortable show-overflow-tooltip>
          <template slot-scope="scope">
            <el-tag v-if="scope.row.type === 0" type="danger">消费</el-tag>
            <el-tag v-if="scope.row.type === 1">收入</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="金额" prop="changeNumber" width="150" show-overflow-tooltip>
          <template slot-scope="scope">
            <span class="color-danger" style="font-size: 15px;font-weight: bold;">{{ scope.row.changeNumber |formatPrice }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="gmtCreated" sortable label="时间" width="160">
          <template slot-scope="scope">{{ scope.row.gmtCreated | formatDate }}</template>
        </el-table-column>
        <el-table-column label="备注" prop="remark" min-width="200" show-overflow-tooltip />
      </el-table>
    </div>
    <div class="pagination_handler">
      <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="fetchData" />
    </div>
  </div>
</template>

<script>
export default {
  components: {},
  props: {
    memberId: {
      type: String,
      default: null
    }

  },

  data() {
    return {
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
            picker.$emit('pick', [start, end])
          }
        }]
      },
      applicationTimes: [],
      list: [],
      total: 0,
      listQuery: {
        page: 1,
        limit: this.common.PAGE_LIMIT_DEFAULT,
        type: '',
        timeStart: null,
        timeEnd: null,
        sort: this.common.SORT_DEFAULT
      },

      multipleSelectionRecords: []
    }
  },
  watch: {
    memberId: {
      handler(val) {
        if (val) {
          this.listQuery = {
            ...this.listQuery,
            memberId: val
          }
          this.fetchData()
        }
      },
      immediate: true
    }
  },
  created() {
  },
  methods: {
    // 表格自带方法开始
    /* 全选/反选*/
    handleSelectionChange(val) {
      this.multipleSelectionRecords = val
    },
    /* 表格行数据单击*/
    handleRowClick(row) {
      this.$refs.multipleTable.toggleRowSelection(row)
    },
    /* 表格列排序*/
    sortChange(data) {
      const { prop, order } = data
      if (prop) {
        if (order === 'ascending') {
          this.listQuery.sort = '+' + prop
        } else {
          this.listQuery.sort = '-' + prop
        }
      } else {
        this.listQuery.sort = this.common.SORT_DEFAULT
      }
      this.handleFilter()
    },
    // 表格自带方法结束

    /* 搜索*/
    handleFilter() {
      this.listQuery = {
        ...this.listQuery,
        page: 1
      }
      this.fetchData()
    },
    /* 重置*/
    handleReset() {
      this.listQuery = {
        ...this.listQuery,
        page: 1,
        limit: this.common.PAGE_LIMIT_DEFAULT,
        type: '',
        timeStart: null,
        timeEnd: null,
        sort: this.common.SORT_DEFAULT
      }
      this.applicationTimes = []
      this.$refs.multipleTable.clearFilter()
      this.$refs.multipleTable.clearSort()
      this.fetchData()
    },
    async fetchData() {
      if (this.applicationTimes.length === 2) {
        this.listQuery = {
          ...this.listQuery,
          timeStart: this.applicationTimes[0],
          timeEnd: this.applicationTimes[1]
        }
      }
      const response = await this.$store.dispatch('memberUserWalletChangePage', this.listQuery)
      this.list = response.records
      this.total = response.total
    }
  }
}
</script>
  <style lang="scss" scoped>
  </style>
